home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cpptutor.arc / FLYAWAY.CPP < prev    next >
Text File  |  1991-04-28  |  11KB  |  341 lines

  1. //       XXXXX  X      X   X    X    X   X    X    X   X
  2. //       X      X      X   X   X X   X   X   X X   X   X
  3. //       X      X       X X   X   X  X   X  X   X   X X
  4. //       XXX    X        X    X   X  X   X  X   X    X
  5. //       X      X        X    XXXXX  X X X  XXXXX    X
  6. //       X      X        X    X   X  X X X  X   X    X
  7. //       X      XXXXX    X    X   X   X X   X   X    X
  8.  
  9. //                    FLYAWAY - version 2.00
  10. //          Written by: Gordon Dodrill - July 20, 1990
  11. //          Copywrite 1989, 1990 - Coronado Enterprises
  12.  
  13. #include "stdio.h"
  14. #include "conio.h"
  15. #include "iostream.h"
  16. #include "flyaway.h"
  17. #include "location.hpp"
  18. #include "items.hpp"
  19. #include "message.h"
  20. #include "schedule.hpp"
  21. #include "clock.hpp"
  22.  
  23.  
  24. word verb, noun;
  25. clock time_of_day;
  26. schedule flight_info;
  27. location your_car;
  28. location pass_drop_off;
  29. location lobby;
  30. location baggage_claim;
  31. location dark_room;
  32. location ticket_counter;
  33. location tunnel;
  34. location rest_room;
  35. location snack_bar;
  36. location security;
  37. location waiting_area;
  38. location gate1;
  39. location gate2;
  40. location gate3;
  41. location gate4;
  42. location plane1;
  43. location plane2;
  44. location plane3;
  45. location plane4;
  46. location *present_location = &your_car;
  47. location *result;
  48. items personal_items;      // The stuff I am carrying
  49.  
  50.  
  51.  
  52.  
  53. main()
  54. {
  55.    initialize();
  56.    cout << " Your best friend offered to drop you off at the airport\n"
  57.            " so you can begin your dream vacation and you have just\n"
  58.            " arrived at the passenger drop off area.  You have about\n"
  59.            " 25 minutes to get to your plane, you haven't had any \n"
  60.            " lunch, and you have a full bladder.  Be very careful, \n"
  61.            " there is a lot of construction going on all around the \n"
  62.            " airport.      Good luck!\n\n"
  63.            " Type help if you want a few clues and a word list.\n\n";
  64.  
  65.    do {
  66.       time_of_day.inc_and_print_time(); // This makes the user prompt
  67.       get_command(verb, noun);          // Get user prompt
  68.       perform_action(verb, noun);       // Try to perform the request
  69.       flight_info.shuffle_flights();
  70.       flight_info.shuffle_gates(present_location);
  71.               // See if the flight has been found and all is in order
  72.       flight_info.check_flight(present_location);
  73.    } while (verb != quit);
  74. }
  75.  
  76.  
  77. void initialize(void)
  78. {
  79.    cout << "            Welcome to Flyaway, version 2.00\n\n";
  80.  
  81.    your_car.init(&pass_drop_off, // North from here
  82.               NULL,              // East from here
  83.               NULL,              // South from here
  84.               NULL,              // West from here
  85.               your_car_message,  // message when entering here
  86.               y_c_look_message); // message for look command
  87.  
  88.    pass_drop_off.init(&lobby,
  89.               NULL,
  90.               NULL,    // You cannot go back to the car, it leaves
  91.               NULL,
  92.               pass_drop_off_message,
  93.               p_d_o_look_message);
  94.  
  95.    lobby.init(&ticket_counter,
  96.               NULL,
  97.               &pass_drop_off,
  98.               &baggage_claim,
  99.               lobby_message,
  100.               l_look_message);
  101.  
  102.    baggage_claim.init(NULL,
  103.               &lobby,
  104.               NULL,
  105.               &dark_room, 
  106.               baggage_claim_message,
  107.               b_c_look_message);
  108.  
  109.    dark_room.init(NULL,
  110.               NULL,
  111.               NULL,
  112.               NULL,
  113.               dark_room_message,
  114.               d_r_look_message);
  115.  
  116.    ticket_counter.init(&tunnel,
  117.               NULL,
  118.               &lobby,
  119.               NULL, 
  120.               ticket_counter_message,
  121.               t_c_look_message);
  122.  
  123.    tunnel.init(&security,
  124.               &snack_bar,
  125.               &ticket_counter,
  126.               &rest_room,
  127.               tunnel_message,
  128.               t_look_message);
  129.  
  130.    rest_room.init(NULL,
  131.               &tunnel,
  132.               NULL,
  133.               NULL,
  134.               rest_room_message,
  135.               r_r_look_message);
  136.  
  137.    snack_bar.init(NULL,
  138.               NULL,
  139.               NULL,
  140.               &tunnel,
  141.               snack_bar_message,
  142.               s_b_look_message);
  143.  
  144.    security.init(&waiting_area,
  145.               NULL,
  146.               &tunnel,
  147.               NULL, 
  148.               security_message,
  149.               s_look_message);
  150.  
  151.    waiting_area.init(NULL,
  152.               &gate3,
  153.               &security,
  154.               &gate2,
  155.               waiting_area_message,
  156.               w_a_look_message);
  157.  
  158.    gate1.init(&plane1,
  159.               &gate2,
  160.               NULL,
  161.               NULL,
  162.               gate1_message,
  163.               g1_look_message);
  164.  
  165.    plane1.init(NULL,
  166.               NULL,
  167.               NULL,
  168.               NULL,
  169.               plane_message,
  170.               plane_look_message);
  171.  
  172.    gate2.init(&plane2,
  173.               &waiting_area,
  174.               NULL,
  175.               &gate1,
  176.               gate2_message,
  177.               g2_look_message);
  178.  
  179.    plane2.init(NULL,
  180.               NULL,
  181.               NULL,
  182.               NULL,
  183.               plane_message,
  184.               plane_look_message);
  185.  
  186.    gate3.init(&plane3,
  187.               &gate4,
  188.               NULL,
  189.               &waiting_area,
  190.               gate3_message,
  191.               g3_look_message);
  192.  
  193.    plane3.init(NULL,
  194.               NULL,
  195.               NULL,
  196.               NULL,
  197.               plane_message,
  198.               plane_look_message);
  199.  
  200.    gate4.init(&plane4,
  201.               NULL,
  202.               NULL,
  203.               &gate3,
  204.               gate4_message,
  205.               g4_look_message);
  206.  
  207.    plane4.init(NULL,
  208.               NULL,
  209.               NULL,
  210.               NULL,
  211.               plane_message,
  212.               plane_look_message);
  213.  
  214.    personal_items.add_item(keys);     // Player gets keys
  215.    personal_items.add_item(money);    // Player gets money
  216.  
  217.    your_car.add_item(ticket);         // Ticket is in car
  218.    snack_bar.add_item(candy);         // Candy is in snack bar
  219. }
  220.  
  221.  
  222.  
  223.  
  224.        // A reference variable is used for the verb so we can get a 
  225.        //  change back to main to end the game when the time comes.
  226. void perform_action(word &verb, word noun)
  227. {
  228.    if (is_a_direction(verb)) {              // Move to a new location
  229.       result = present_location->move(verb);
  230.       if (result) {                  // If Non-NULL
  231.          present_location = result;  // Valid move found
  232.          present_location->display_message();
  233.       }
  234.  
  235.                                  // Force end of game if in dark room
  236.       if (present_location == &dark_room) {
  237.          verb = quit;
  238.          cout << "Hit any key to end the game.";
  239.          int c = getch();
  240.       }
  241.    }
  242.  
  243.                                                          // Inventory
  244.    else if (verb == inventory)
  245.       personal_items.list_items();
  246.  
  247.                                                               // Look
  248.    else if (verb == look)
  249.       present_location->display_list_of_items();
  250.  
  251.                                                          // Drop item
  252.    else if (verb == drop) {
  253.       if (personal_items.item_here(noun)) {
  254.          personal_items.drop_item(noun);
  255.          present_location->add_item(noun);
  256.          cout << " Dropped.\n";
  257.       } else {
  258.          cout << "You can't drop what you don't have.\n";
  259.       }
  260.    }
  261.  
  262.                                                           // Get item
  263.    else if (verb == get) {
  264.       if (present_location->item_here(noun)) {
  265.          present_location->drop_item(noun);
  266.          personal_items.add_item(noun);
  267.          cout << " Picked up.\n";
  268.       } else {
  269.          cout << "It isn't here so you can't pick it up.\n";
  270.       }
  271.    }
  272.  
  273.                                                          // Buy candy
  274.    else if ((verb == buy) && (noun == candy) && 
  275.                            (present_location == &snack_bar)) {
  276.       if ((personal_items.item_here(money)) &&
  277.                            (present_location->item_here(candy))) {
  278.          personal_items.drop_item(money);
  279.          personal_items.add_item(candy);
  280.          present_location->drop_item(candy);
  281.          present_location->add_item(money);
  282.          cout << " You now have candy.\n";
  283.       } else 
  284.          cout << "Surely you are not serious about that!\n";
  285.    }
  286.  
  287.                                                        // Read ticket
  288.    else if ((verb == read) && (noun == ticket)) 
  289.       if (personal_items.item_here(ticket))
  290.          flight_info.list_actual_destination();
  291.       else
  292.          cout << "You don't have a ticket to read.\n";
  293.  
  294.                                                       // Read monitor
  295.    else if ((verb == read) && (noun == monitor) &&
  296.             (present_location == &ticket_counter)) 
  297.       flight_info.list_flights(present_location);
  298.  
  299.                                                       // Read monitor
  300.    else if ((verb == read) && (noun == monitor) &&
  301.             (present_location == &waiting_area)) 
  302.       flight_info.list_flights(present_location);
  303.  
  304.                                                         // Read paper
  305.    else if ((verb == read) && (noun == paper) && 
  306.                                     (present_location == &lobby))
  307.       cout <<
  308.        "\n                C++ TUTORIAL RELEASED\n"
  309.        "Coronado Enterprises has a full line of computer language\n"
  310.        "programming tutorials available.  Write and ask for the\n"
  311.        "latest information.\n"
  312.        "   Coronado Enterprises\n"
  313.        "   12501 Coronado Ave NE\n"
  314.        "   Albuquerque, NM 87122\n\n"
  315.        "There is another story about danger at the airport due to\n"
  316.        "construction.  Be very careful!\n";
  317.  
  318.                                                               // Help
  319.    else if (verb == help)
  320.       cout << 
  321.       "Each action requires a verb, or a verb and a noun, and only\n"
  322.       "the first two words of the command are significant, any \n"
  323.       "other words on a line are ignored.  The four directions can\n"
  324.       "be abbreviated to the first letter to make it easier to get\n"
  325.       "to your flight.  The entire vocabulary is given as;\n\n"
  326.       "      ------- verbs -------          ---- nouns ----\n"
  327.       "      north   drop   read            keys    money\n"
  328.       "      east    get    buy             candy   monitor\n"
  329.       "      south   look   help            ticket  paper\n"
  330.       "      west    quit   inventory\n\n"
  331.       "   look = give more information on current location\n"
  332.       "   inventory = list items I am carrying\n\n"
  333.       "You better hurry, you just wasted a minute reading this.\n\n";
  334.                                                               // Quit
  335.    else if (verb == quit) ;  // Ignore to prevent message
  336.  
  337.    else
  338.       cout << "I don't understand what you want.\n";
  339.  
  340. }
  341.